<template>
  <!-- <div>这是公司概况的二级目录下内容管理</div> -->
  <div class="CompanyContent-container">
    <el-card class="box-card">
      <div slot="header" class="clearfix">

        <el-table
          :data="CompanyContent"
          style="width: 100%"
        >
          <el-table-column
            prop="contentId"
            label="ID"
            width="100"
          />
          <el-table-column
            prop="ownedDirectory"
            label="所属二级目录id"
            width="120"
          />
          <el-table-column label="操作" align="center">
            <template slot-scope="scope">
              <el-button
                size="mini"
                @click="handleClick(scope.row)"
              >查看</el-button>
              <el-button
                size="mini"
                @click="handleEdit(scope.$index, scope.row)"
              >编辑</el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>
    </el-card>
    <el-dialog :title="titleMap[dialogStatus]" :visible.sync="dialogForm">
      <el-form :model="form">
        <el-form-item label="Id" :label-width="formLabelWidth">
          <el-input v-model="editForm.contentId" autocomplete="off" />
        </el-form-item>
        <el-form-item label="所属二级目录Id" :label-width="formLabelWidth">
          <el-input v-model="editForm.ownedDirectory" autocomplete="off" />
        </el-form-item>
        <el-form-item label="内容" :label-width="formLabelWidth">
          <el-input
            v-model="editForm.content"
            type="textarea"
            autocomplete="off"
            :rows="20"
          />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click.native="handleCancel('editForm')">取 消</el-button>
        <el-button type="primary" @click.native="handleUpdate('editForm')">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  getCompanyContent,
  modifyCompanyContent
} from '@/api/Company'

export default {
  data() {
    return {
      CompanyContent: [],
      dialogForm: false,
      editForm: {
        contentId: '',
        ownedDirectory: '',
        content: ''
      },
      titleMap: {
        edit: '编辑'
      },
      dialogStatus: '',
      flag: 0
    }
  },
  created() {
    this.loadCompanyContent()
  },
  mounted() {},
  methods: {
    loadCompanyContent() {
      getCompanyContent().then(res => {
        console.log(res)
        this.CompanyContent = res.data
      })
    },

    handleEdit: function(index, row) {
      this.dialogForm = true
      this.editForm = Object.assign({}, row)
      this.dialogStatus = 'edit'
    },

    handleUpdate: function(editForm) {
      modifyCompanyContent(this.editForm).then(res => {
        console.log(res)
        this.loadCompanyContent()
      })
      this.$message({
        type: 'success',
        message: '修改成功'
      })
      this.dialogForm = false
    },

    handleCancel(editForm) {
      this.$message({
        type: 'info',
        message: '已取消'
      })
      this.dialogForm = false
    }
  }
}
</script>

<style></style>
